package logic

import (
	"context"
	"go-zero-project-02/rpc_study/user_api_rpc/rpc/userclient"

	"go-zero-project-02/rpc_study/user_api_rpc/api/internal/svc"
	"go-zero-project-02/rpc_study/user_api_rpc/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserCreateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserCreateLogic {
	return &UserCreateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserCreateLogic) UserCreate(req *types.UserCreateRequest) (resp string, err error) {
	response, err := l.svcCtx.UserRpc.UserCreate(l.ctx,
		&userclient.UserCreateRequest{
			Username: req.UserName,
			Password: req.Password,
		})
	logx.Infof("调用rpc-创建用户信息---Username:%v Password：%v", req.UserName, req.Password)
	if err != nil {
		return "", err
	}
	if response.Err != "" {
		return "", err
	}
	return "", nil
}
